import OrgSelect from '@/components/Process/OrgSelect'
import request from '@/utils/request'
import { mapGetters } from 'vuex'
export default {
  components: { OrgSelect },
  props: [],
  data() {
    return {
      loading: false,
      visible: false,
      dataForm: {
        ids: undefined,
        counselor: undefined
      },
      rules: {
        time: [
          {
            required: true,
            message: '请选择转让时间',
            trigger: 'change'
          }
        ],
        description: [
          {
            required: true,
            message: '请添加转让说明',
            trigger: 'blur'
          }
        ]
      },
      type: ''
    }
  },
  computed: {
    ...mapGetters(['allocationhandleSelection'])
  },
  watch: {},
  mounted() {},
  methods: {
    getConsole(res) {
      console.log(res)
    },
    deleteSelection(index) {
      this.$store.dispatch('allocation/handleSelectionDelete', index)
    },
    handleClose(done) {
      this.$emit('refresh', true)
      done()
    },
    onClose() {
      this.visible = false
      this.$emit('refresh', true)
    },
    goBack() {
      this.$emit('refresh')
    },
    init(type) {
      console.log(this.$store, '$store')
      this.visible = true
      this.type = type
      this.$nextTick(() => {
        this.$refs['elForm'].resetFields()
      })
    },
    dataFormSubmit() {
      this.$refs['elForm'].validate(valid => {
        if (valid) {
          let campusIds = this.allocationhandleSelection.map(item => item.id)
          let arr =
            this.type === 1
              ? {
                  counselor: this.dataForm.counselor
                }
              : {
                  supervisor: this.dataForm.counselor
                }
          let postData = {
            campusIds: campusIds,
            ...arr
          }
          this.loading = true
          let url = this.type === 1 ? '/api/campus/batch/set/counselor' : '/api/campus/batch/set/supervisor'
          request({
            url: url,
            method: 'post',
            data: postData
          })
            .then(res => {
              this.$message({
                message: res.msg,
                type: 'success',
                duration: 1000,
                onClose: () => {
                  this.visible = false
                  this.loading = false
                  this.$store.dispatch('allocation/handleSelectionClear')
                  this.$emit('refresh', true)
                }
              })
            })
            .catch(() => {
              this.loading = false
            })
        }
      })
    }
  }
}
